﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="selfdispatchh5.aspx.cs" Inherits="Html5.selfdispatchh5" %>


<%@ Register Src="~/footer.ascx" TagName="Foot" TagPrefix="uc2" %>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <title><%= SectionProxyData.GetSetValue(3) %></title>

    <link type="text/css" rel="stylesheet" href="/css/style.css" />
    <link type="text/css" rel="stylesheet" href="/css/page.css" />
    <link href="../css/sweetalert.css" rel="stylesheet" />
    <link href="../css/shopcenter.css" rel="stylesheet" />
    <script type="text/javascript" src="/javascript/jquery.js"></script>

    <style type="text/css">
        .bom_menu .icon-order {
            background-image: url(/images/ico_b_order_cur.png);
        }

        #page_title .top_shop {
            background: url(/images/shop_top_search.png) no-repeat;
            height: 32px;
            width: 32px;
            background-size: 100% 100%;
            margin-top: 5px;
        }
    </style>


</head>
<body>

    <input type="hidden" runat="server" id="hfcityid" value="0" />
    <input type="hidden" runat="server" id="hfgid" value="0" />

    <div class="page">

        <div id="page_title">
            <a href="publishorder.aspx" id="back" class=" top_left" data-ajax="false"><span style="padding-left: 15px; width: 50px; position: absolute; top: -10px; font-size: 14px;">发单</span></a>
            <h1>发给附近配送员</h1>
            <a id="togourl" class="top_shop top_right" href="javascript:" onclick="$('#searchbox').toggle()"></a>
        </div>

        <div class="container ">

            <div id="searchbox" style="display: none;">

                <ul class="my_order_list">
                    <li>
                        <div class="order-tit">
                            <span class="time"><strong>配送员/电话</strong>
                                <input name="tbkey" type="text" id="tbkey" class="w_txt" placeholder="请输入配送员名称" />
                            </span>
                        </div>

                        <div class="order-tit" style="border-bottom: none; padding: 0;">
                            <span class="time"><strong>配送员状态</strong>
                                <select id="ddlstate" runat="server">
                                    <option value="-1">所有</option>
                                    <option value="10">待岗</option>
                                    <option value="20">取货中</option>
                                    <option value="30">送货中</option>
        

                                </select>
                            </span>
                        </div>


                    </li>
                </ul>

                <div class="order-tit">
                    <div class="view_back_con">
                        <input type="submit" value="搜索" onclick="searchorder()" class="view_back_btn" data-ajax="false" />



                    </div>
                </div>
            </div>



            <div class="order-tit" style="margin-top: 20px;">
                <div class="view_back_con">
                    <input type="button" value="发送给客服调度" onclick="dispatch2Service(this)" class="view_back_btn" data-ajax="false" style="width: 40%" />

                    <input type="button" value="自动选择配送员" onclick="shopautodispatch(this)" class="view_back_btn" data-ajax="false" style="width: 40%; margin-left: 10px" />

                </div>
            </div>


            <ul class="my_order_list">
                <asp:Repeater runat="server" ID="rptorder">
                    <ItemTemplate>
                        <li class="deliveritem">
                            <div class="order-tit">
                                <span class="time"><%# Eval("Name")%>【<%# Hangjing.WebCommon.WebHelper.TurnWorkstate( Eval("workstate"))%>】</span>
                                <span class="state"><%# Eval("Phone") %></span>
                            </div>
                            <div class="order-info" style="background: none;">
                                <p class="f14">距离：<span class="red"><%# Eval("distance") %>米</span><span style="margin-left: 20px">手上订单：<span class="red"><%# Eval("processcount")%></span>单</span></p>
                            </div>
                            <div class="view_back_con">
                                <input type="button" value="发给他" class="view_back_btn" data-name="<%# Eval("Name") %>" data-did="<%# Eval("dataid") %>" onclick="dispatch2deliver(this); return false;" data-ajax="false" style="border-radius: 5px;" />
                            </div>
                        </li>
                    </ItemTemplate>
                </asp:Repeater>
            </ul>

        </div>
    </div>
</body>
</html>

<script src="../javascript/jCommon.js"></script>
<script src="../javascript/sweetalert.min.js"></script>
<script src="../javascript/spin.min.js"></script>

<script type="text/javascript">

    function searchorder() {
        var url = "selfdispatchh5.aspx?a=1";
        var tbkey = $.trim($("#tbkey").val());
        if (tbkey.length > 0) {
            url += "&key=" + tbkey;
        }

        var ddlstate = $.trim($("#ddlstate").val());
        if (ddlstate != "-1") {
            url += "&state=" + ddlstate;
        }

        var id = request("id");
        var lat = request("lat");
        var lng = request("lng");

        url += "&id=" + id;
        url += "&lat=" + lat;
        url += "&lng=" + lng;

        window.location = url;

    }

    $(document).ready(function () {
        var tbkey = request("key")
        if (tbkey.length > 0) {
            $("#tbkey").val(tbkey);
            $("#searchbox").show();
        }
        var state = request("state")
        if (state.length > 0) {
            $("#ddlstate").val(state);
            $("#searchbox").show();
        }

        if ($(".deliveritem").length == 0) {

            swal({
                title: "温馨提示",
                text: "订单提交成功,但是附近没有配送员订单已经直接转到客服调度了",
                type: "warning"
            },
               function () {
                   window.location = "publishorder.aspx";
               });

        }
    });

    //调度给配送员
    function dispatch2deliver(target) {

        Loader.show(target);

        var name = $(target).attr("data-name");
        var d_id = $(target).attr("data-did");
        var id = request("id");

        var url = "/ajaxHandler.ashx";
        var para = "method=shopSpreadOne2deliver&did=" + d_id + "&t=" + new Date().getTime() + "&oids=" + id + "&name=" + escape(name);
        jQuery.ajax(
        {
            type: "post",
            url: url,
            data: para,
            success: function (msg) {

                swal({
                    title: "温馨提示",
                    text: "调度成功，点击继续下单",
                    type: "success"
                },
                        function () {
                            window.location = "publishorder.aspx";
                        });
            }
        })
    }

    // 订单返回客服
    function dispatch2Service(target) {

        Loader.show(target);
        var id = request("id");

        var url = "/ajaxHandler.ashx";
        var para = "method=dispatch2Service&id=" + id + "&t=" + new Date().getTime();
        jQuery.ajax(
        {
            type: "post",
            url: url,
            data: para,
            success: function (msg) {

                swal({
                    title: "温馨提示",
                    text: "订单已经发送给客服，点击继续下单",
                    type: "success"
                },
                        function () {
                            window.location = "publishorder.aspx";
                        });
            }
        })

    }

    //商家自动调度
    function shopautodispatch(target) {

        Loader.show(target);
        var id = request("id");
        var lat = request("lat");
        var lng = request("lng");
        var cityid = $.trim($("#hfcityid").val());
        var gid = $.trim($("#hfgid").val());

        var url = "/ajaxHandler.ashx";
        var para = "method=shopautodispatch&id=" + id + "&t=" + new Date().getTime() + "&lat=" + lat + "&lng=" + lng + "&cityid=" + cityid + "&gid=" + gid;
        jQuery.ajax(
        {
            type: "post",
            url: url,
            data: para,
            success: function (msg) {
                var json = eval("(" + msg + ")");
                var type = "success";
                if (json.state == "0") {
                    type = "warning";
                }

                swal({
                    title: "温馨提示",
                    text: json.msg,
                    type: type
                },
                        function () {
                            window.location = "publishorder.aspx";
                        });





            }
        })

    }


</script>
